<template>
  <el-form-item label="原价" prop="originalPrice" :rules="rules" class="common-form-width">
    <el-input
        v-model="modelValue"
        :disabled="disabled"
        placeholder="请输入原价"
        maxlength="15"
        show-word-limit
        @blur="modelValue = $event.target.value.trim()"
    >
      <template #append>
        元
      </template>
    </el-input>
  </el-form-item>
</template>

<script lang="ts" setup>
import {positiveNumber_decimal$2} from "@/utils/commonRegexp";

const props = withDefaults(defineProps<{
  modelValue: number,
  disabled?: boolean
}>(), {
  modelValue: 0,
  disabled: false
})

const emits = defineEmits(['update:model-value'])
const modelValue = computed({
  set(newValue) {
    emits("update:model-value", newValue)
  },
  get() {
    return props.modelValue
  }
})

const rules = [
  {
    message: '请输入原价', required: true, trigger: 'blur'
  },
  {
    trigger: 'blur',
    validator(rules: any, value: any, callback: any) {
      if (props.disabled) {
        callback()
        return
      }

      if (positiveNumber_decimal$2.test(props.modelValue + '')) {
        callback('请输入原价，需大于0，保留2位小数')
        return
      }

      callback()
    }
  }
]

</script>

<style scoped lang="scss">
@use "@/components/goodsCenter/styles/common.scss";
</style>
